package com.bonc.event.extractor;

import java.util.Set;

//import org.apache.clerezza.rdf.core.UriRef;

/**
 * 
 * @author Cristian Petroaca
 *
 */
public class Rule {
	/**
	 * The unique id of the rule
	 */
	private String id;

	/**
	 * The set of {@link Trigger}s which can lead to identifying an Event based
	 * on this rule
	 */
	private Set<Trigger> triggers;

	/**
	 * The set of {@link ThematicRelation}s
	 */
	private Set<ThematicRelation> thematicRelations;

	public Rule(String id, Set<Trigger> triggers, Set<ThematicRelation> thematicRelations) {
		if (id == null || id.equals("")) {
//		if (id == null || id.getUnicodeString().equals("")) {
			throw new IllegalArgumentException("id must not be null or empty");
		}
		
		if (triggers == null || triggers.isEmpty()) {
			throw new IllegalArgumentException("triggers must not be null or empty");
		}
		
		if (thematicRelations == null || thematicRelations.isEmpty()) {
			throw new IllegalArgumentException("thematicRelations must not be null or empty");
		}
		
		this.id = id;
		this.triggers = triggers;
		this.thematicRelations = thematicRelations;
	}

	public String getId() {
		return id;
	}

	public Set<Trigger> getTriggers() {
		return triggers;
	}

	public Set<ThematicRelation> getThematicRelations() {
		return thematicRelations;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id.hashCode();
		result = prime * result + triggers.hashCode();
		result = prime * result + thematicRelations.hashCode();

		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		Rule other = (Rule) obj;

		return id.equals(other.id) && triggers.equals(other.triggers)
				&& thematicRelations.equals(other.thematicRelations);
	}
}
